package org.ws.edu;

import java.io.IOException;
import java.net.ServerSocket;

import org.apache.log4j.Logger;
import org.ws.edu.core.TestManagerThread;

/**
 * Main class.
 * 
 * Ths class has main method that launch server
 * 
 * @version 1
 * @author Jimotozka
 */
public class StartServer {
    private static Logger logger = Logger.getLogger(StartServer.class);

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try {
            try {
                serverSocket = new ServerSocket(4444);

            } catch (IOException e) {
                logger.warn("Could not listen on port: 4444", e);
                System.exit(-1);
            }
            while (true) {
                try {
                    new TestManagerThread(serverSocket.accept()).start();
                } catch (IOException e) {
                    logger.warn("Could not create socket", e);
                    System.exit(-1);
                }
            }
        } finally {
            try {
                serverSocket.close();
            } catch (IOException e) {
                logger.warn("Could not close socket", e);
            }
        }
    }
}